'use strict';

function _asyncToGenerator(fn) { return function () { var gen = fn.apply(this, arguments); return new Promise(function (resolve, reject) { function step(key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { return Promise.resolve(value).then(function (value) { step("next", value); }, function (err) { step("throw", err); }); } } return step("next"); }); }; }

Vue.component('category-add', {
    props: ['parentid', 'module', 'add_url', 'lst_url', 'mod_url', 'del_url', 'preview_url'],
    template: '\n<el-form ref="form" :model="form" label-width="100px" style="width:600px;margin:0 auto;">\n  <el-form-item label="\u4E0A\u7EA7\u5206\u7C7B">\n    <el-select v-model="form.parentid" placeholder="">\n      <el-option :key="0" :value="0" label="\u8BF7\u9009\u62E9">\u8BF7\u9009\u62E9</el-option>\n      <el-option :key="item.catid" :value="item.catid" :label="item.catname" v-for="item in category_select">\n      {{\'&nbsp;&nbsp;&nbsp;&nbsp;\'.repeat(item.lev)+\'\u2516\u2500&nbsp;\'+item.catname}}\n</el-option>\n      \n    </el-select>\n  </el-form-item>\n  <el-form-item label="\u5206\u7C7B\u540D\u79F0">\n    <el-input v-model="form.catname"></el-input>\n  </el-form-item>\n  <el-form-item>\n    <el-button type="primary" @click="onSubmit">\u63D0\u4EA4</el-button>\n  </el-form-item>\n</el-form>\n',
    data: function data() {
        return {
            form: {
                parentid: parseInt(this.parentid) || 0,
                catname: ''
            },
            category_select: []
        };
    },

    methods: {
        onSubmit: function () {
            var _ref = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee() {
                var response, _data;

                return regeneratorRuntime.wrap(function _callee$(_context) {
                    while (1) {
                        switch (_context.prev = _context.next) {
                            case 0:
                                _context.prev = 0;
                                _context.next = 3;
                                return axios.post(this.add_url, this.form);

                            case 3:
                                response = _context.sent;
                                _data = response.data;

                                if (parseInt(_data.code) > 0) {
                                    this.$message({
                                        message: _data.msg,
                                        type: "success",
                                        duration: 1000
                                    });
                                    setTimeout(function () {
                                        location.reload();
                                    }, 1000);
                                } else {
                                    this.$message.error(_data.msg);
                                }
                                _context.next = 11;
                                break;

                            case 8:
                                _context.prev = 8;
                                _context.t0 = _context['catch'](0);

                                this.$message.error(data.msg);

                            case 11:
                            case 'end':
                                return _context.stop();
                        }
                    }
                }, _callee, this, [[0, 8]]);
            }));

            function onSubmit() {
                return _ref.apply(this, arguments);
            }

            return onSubmit;
        }()
    },
    created: function created() {},
    mounted: function () {
        var _ref2 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee2() {
            var response, _data2;

            return regeneratorRuntime.wrap(function _callee2$(_context2) {
                while (1) {
                    switch (_context2.prev = _context2.next) {
                        case 0:
                            _context2.prev = 0;
                            _context2.next = 3;
                            return axios.post(this.lst_url, {});

                        case 3:
                            response = _context2.sent;
                            _data2 = response.data;

                            if (parseInt(_data2.code) > 0) {
                                this.category_select = _data2.data;
                            } else {
                                this.$message.error(_data2.msg);
                            }
                            _context2.next = 11;
                            break;

                        case 8:
                            _context2.prev = 8;
                            _context2.t0 = _context2['catch'](0);

                            this.$message.error(_context2.t0.toString());

                        case 11:
                        case 'end':
                            return _context2.stop();
                    }
                }
            }, _callee2, this, [[0, 8]]);
        }));

        function mounted() {
            return _ref2.apply(this, arguments);
        }

        return mounted;
    }()
});